package com.gsit.ocrbatch.controller;

import com.gsit.ocrbatch.domain.MessageConfig;
import com.gsit.ocrbatch.domain.Record;
import com.gsit.ocrbatch.utils.MessageUtil;

public class MessageProcesser extends Thread{
	
	private Record record;
	private MessageConfig messageConfig;
	
	public MessageProcesser(Record record, MessageConfig messageConfig) {
		super();
		this.record = record;
		this.messageConfig = messageConfig;
	}

	public void execute()throws Exception{
		this.setName("MessageProcesser");
		this.start();
	}
	
	
	@Override
	public void run() {
        Runtime runtime = Runtime.getRuntime();
        Process process = null;
        try {
        	
        	StringBuffer msgBuffer = new StringBuffer("msg /server:");  
        	msgBuffer.append(messageConfig.getIpAddress());
        	msgBuffer.append(" console ");
        	msgBuffer.append(" \"");
        	msgBuffer.append(MessageUtil.getMessage(record.getRecordRejects()));
        	msgBuffer.append(" \"");
        	//msgBuffer.append(" \" message is reject  \"");
                //String command = "net send " + messageConfig.getIpAddress() + " " + "start message for next flow";
                System.out.println("Command :"+msgBuffer.toString());
                process = runtime.exec(msgBuffer.toString());
                //process.getOutputStream()
        } catch (Exception e) {
                System.out.println(e);
        }
} 

}
